package com.example.yiwei.crm.json;

import android.util.Log;

import com.example.yiwei.crm.entity.QXEntity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by DHN on 2017/5/26.
 */

public class QXjson {


    public static List<QXEntity> get(String result){
        List<QXEntity> list;
        QXEntity qxEntity;
        QXEntity qxEntity1;
        try {
            Log.d("cc",result);
            list = new ArrayList<>();
            JSONObject object = new JSONObject(result);
            JSONArray array  = object.getJSONArray("menuList");
            JSONObject object1 = array.getJSONObject(0);
            JSONArray array1 = object1.getJSONArray("children");
            for (int i=0;i<array1.length();i++){
                qxEntity = new QXEntity();
                JSONObject object2 = array1.getJSONObject(i);
                if (object2.has("UAD03")){
                    qxEntity.setName(object2.getString("UAD03"));
                }
                if (object2.has("UAD05")){
                    qxEntity.setContent(object2.getString("UAD05"));
                }
                if (object2.has("children")){
                    JSONArray array2 = object2.getJSONArray("children");
                    for (int i1=0;i1<array2.length();i1++) {
                        qxEntity1 = new QXEntity();
                        JSONObject object3 = array2.getJSONObject(i1);
                        if (object3.has("UAD03")) {
                            qxEntity1.setName(object3.getString("UAD03"));
                        }
                        if (object3.has("UAD05")) {
                            qxEntity1.setContent(object3.getString("UAD05"));
                        }
                        list.add(qxEntity1);
                    }
                }
                list.add(qxEntity);
            }
           return list;
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
}
